<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<!-- Casting SPELs in Lisp - Emacs Lisp Edition, a Comic Book
     Written by Conrad Barski, M.D., http://lisperati.com
     Edited by James A. Webb, http://uberkode.com -->

<head>

  <title>Casting SPELs in Lisp (12)</title>
  <meta http-equiv="content-type" content="text/html;charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="author" content="James A. Webb" />
  <meta name="date" content="2007-09-15T00:00:00+00:00" />
  <meta name="keywords" content="Emacs, Lisp" />

</head>

<body>

<center>

<table cellspacing="10" width="500">
  <tr>
    <td bgcolor="#AAFFAA" height="50" align="center">
        <b>Looking Around in our Game World</b>
    </td>
  </tr>
  <tr>
    <td>
      The first command we'd want to have is one that tells us
      about the location we're standing in. So what would a function
      need to describe a location in a world? Well, it would need to
      know the location we want to describe and be able to look at a 
      map and find that location on the map. Here's our function, and 
      it does exactly that:
    </td>
  </tr>
  <tr>
    <td>
<pre style="font-weight: bolder; color: darkblue">
  (defun describe-location (location map)
    (second (assoc location map)))
</pre>
    </td>
  </tr>
  <tr>
    <td>
      The word <tt>defun</tt> means, as you might expect, that we're 
      defining a function. The name of the function is 
      <tt>describe-location</tt> and it takes two parameters: a location 
      and a map. These variables are local parameters of a function 
      and hence unrelated to the global <tt>lisp-adventure-location</tt> 
      and <tt>lisp-adventure-map</tt> variables. Note that functions in 
      Lisp are often more like functions in math than in other 
      programming languages: If you can remember back to your 
      pre-algebra class, a <i>math function</i> is just a relationship 
      between a bunch of inputs (called the <i>domain</i>) to an output 
      (called the <i>range</i>.) In math, you would never have a function 
      that pops up a message box or prints stuff for the user to read - 
      Our function <tt>describe-location</tt> is a lot like that, because 
      it is a function that just calculates a value (in this case, the 
      description of a location on our map.) Let's imagine our 
      location is in the living-room (which, indeed, it is...) 
    </td>
  </tr>
  <tr>
    <td align="center">
      &lt;&lt; <a href="casting-spels-emacs-1.html">begin</a>
      &lt; <a href="casting-spels-emacs-11.html">previous</a> - 
      <a href="casting-spels-emacs-13.html">next</a> &gt;
      <a href="casting-spels-emacs-35.html" >end</a> &gt;&gt;
    </td>
  </tr>
</table>

</center>

</body>

</html>